package org;

import org.classloaders.CompilingClassLoader;
import org.testclasses.TestModule;

import java.io.IOException;

/**
 * Created by OleR on 24.07.14.
 */
public class Main {

    /**
     * Full name of class we want to load in runtime
     * with our custom class loader.
     */
    private static final String CLASS_NAME = "org.testclasses.TestModule";

    /**
     * Compiles (is necessary) and loads out testing class.
     *
     * @return loaded class
     */
    private static Object getTestModule() {

        CompilingClassLoader ccl = new CompilingClassLoader();
        Class clas = null;
        Object result = null;

        try {
            clas = ccl.loadClass(CLASS_NAME);
            result = clas.newInstance();
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }

        return result;
    }

    /**
     * Program's entry point.
     *
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

		System.out.println(getTestModule().toString());
		System.in.read();
		System.out.println(getTestModule().toString());

    }
}
